{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "353a7585",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd8b3eda",
   "metadata": {},
   "source": [
    "## np.random.seed：\n",
    "\n",
    "用于指定随机数生成时所用算法开始的整数值，如果使用相同的`seed()`值，则每次生成的随即数都相同，如果不设置这个值，则系统根据时间来自己选择这个值，此时每次生成的随机数因时间差异而不同。一般没有特殊要求不用设置。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "02343926",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.31342418, 0.69232262, 0.87638915],\n",
       "       [0.89460666, 0.08504421, 0.03905478]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.random.seed(1)\n",
    "np.random.rand()\n",
    "np.random.rand(2,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56325257",
   "metadata": {},
   "source": [
    "## np.random.rand：\n",
    "\n",
    "生成一个值为`[0,1)`之间的数组，形状由参数指定，如果没有参数，那么将返回一个随机值。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94855b16",
   "metadata": {},
   "source": [
    "## np.random.randn：\n",
    "\n",
    "生成均值\\(μ\\)为0，标准差（σ）为1的标准正态分布的值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "01626b29",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.17242820755043575"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randn()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fdc155a",
   "metadata": {},
   "source": [
    "## np.random.randint：\n",
    "\n",
    "生成指定范围内的随机数，并且可以通过`size`参数指定维度。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eda13b42",
   "metadata": {},
   "source": [
    "## np.random.choice：\n",
    "\n",
    "从一个列表或者数组中，随机进行采样。或者是从指定的区间中进行采样，采样个数可以通过参数指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ba7ee7df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = np.arange(5)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3eba5139",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 9, 3, 6, 8],\n",
       "       [0, 2, 7, 7, 9]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.choice(data,size=(3,4))\n",
    "np.random.choice(10,size=(2,5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82c32006",
   "metadata": {},
   "source": [
    "## np.random.shuffle：\n",
    "\n",
    "把原来数组的元素的位置打乱。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f13626dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "[9 6 1 8 5 0 2 4 3 7]\n"
     ]
    }
   ],
   "source": [
    "data1 = np.arange(10)\n",
    "print(data1)\n",
    "np.random.shuffle(data1)\n",
    "print(data1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
